<?php
// +----------------------------------------------------------------------
// | wttai [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.wttai.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老司机 <wutongtai@wttai.com> <http://www.wttai.com>
// +----------------------------------------------------------------------
namespace Common\Model;
use Think\Model;


/**
 * 文档基础模型
 */
class ArticleCategoryModel extends BaseModel{


    /**
     * 获取文章分类或标签
     * @param int $article_id 文章id
     * @param int $type 类型 1分类 ，2 标签
     * @return array $result 标签或标签数组
     * 
     */
    public function get_association_tags($article_id,$type){

        if (empty($article_id)) {
            return FALSE;
        }
        $map['article_id'] = $article_id;
        $category_arr = $this->field('category_id')->where($map)->order('category_id',ASC)->getField('category_id',TRUE);
        $map['pid'] = $type;
        if (empty($category_arr)){
            return array('index'=>'暂无数据');
        }else if (in_array($type, $category_arr)){
            $result =D('category')->where($map)->getField('name,title',TRUE);
            return $result;
        }else {
            $map['id'] = array('in',$category_arr);
            $result =D('category')->where($map)->getField('name,title',TRUE);
            return $result;
        }
    }
    
    
}
